<?php
namespace app\admin\controller;
use \think\Controller;
use \think\Db;
class ClubAdmin extends Common
{
	public function index(){

    $clubs=Db::name("clubs")->select();
    $this->assign("clubs",$clubs);

    $clubadmins=Db::query('select * from clubadmins v,clubs t where v.c_id=t.c_id order by v.ca_id asc');
    $this->assign("clubadmins",$clubadmins);
    return $this->fetch('C:\wamp\www\sport\public/../application/admin\view\ClubAdmin\index.html');
		
	/*$clubadmins=Db::name("clubadmins")->select();
	$this->assign("clubadmins",$clubadmins);
	return $this->fetch('D:\wamp\www\sport\public/../application/admin\view\ClubAdmin\index.html');*/
  }
  public function jiekou(){
  $rs=db('clubadmins')->select();
  /*$rs1=json(0,'数据返回成功',1000,$rs); */
   // dump($rs1);die;//打印出来
  return json($rs);
}

  public function add(){
    if (request()->isPost()) {
     //创建数组，给video表的所有字段赋值
      $data=[
       'ca_name'=>input('param.ca_name'),
       'ca_password'=>md5(input('param.ca_password')),
        'ca_tel'=>input('param.ca_tel'),
        'ca_gender'=>input('param.ca_gender'),
        'c_id'=>input('param.c_name'),
      ];

      $validate=\think\Loader::validate('ClubAdmin');
      if (!$validate->check($data)) {
      	$this->error($validate->getError());
      }
      //存入数据库
    $res=Db::name("clubadmins")->insert($data);
    //处理结果
    if ($res) {
      $this->success("添加成功");
    }else{
      $this->error("添加失败");
    }
    }
  }


  public function edit(){
    $ca_id=input('ca_id');
    $clubadmins=Db::name("clubadmins")->find($ca_id);
    echo json_encode($clubadmins);
  }
  public function update(){
      $data=[
        'ca_name'=>input('param.ca_name'),
       'ca_password'=>md5(input('param.ca_password')),
        'ca_tel'=>input('param.ca_tel'),
        'ca_gender'=>input('param.ca_gender'),
        'c_id'=>input('param.c_name'),
      ];
$ca_id=input('param.ca_id');
var_dump($data);
//修改数表
      if(Db::name('clubadmins')->where("ca_id",$ca_id)->update($data)){
        $this->success('修改成功');
      }else{
        $this->error('修改失败');
      }
    }

public function delete($id){

    if (Db::name("clubadmins")->delete($id)) {
      $this->success('删除成功');
    }else $this->error('删除失败');
  }
}
